package work.demo;

import work.config.Constant;
import work.fram.KeyValueMapper;
import work.fram.SqlMaker;
import work.person.helper.ConditionHelper;
import work.utils.CommonExcelUtils;
import work.utils.TextUtils;

import java.io.File;
import java.util.List;
import java.util.Map;

//禁用组织机构
public class OrgForbidden {

    public static void main(String[] args) {
        List<Map<String, String>> list = CommonExcelUtils.e2m(new File(Constant.work, "全量机构数据(1).xls"), "Sheet1", 0);

        SqlMaker sqlMaker = new SqlMaker("f_organization");
        SqlMaker sqlMaker1 = new SqlMaker("md_organization");
        KeyValueMapper mapper = sqlMaker.createKeyValueMapper();
        KeyValueMapper mapper1 = sqlMaker1.createKeyValueMapper();

        StringBuilder builder = new StringBuilder();

        for (Map<String, String> map : list) {
            mapper.reset();
            mapper1.reset();

            System.out.println(map);

            switch (map.get("sorg_is_disabled")) {
                case "禁用":
                    //放入sorg_is_disabled
                    mapper.put("isDisabled", "true");
                    if (sqlMaker.make(SqlMaker.TYPE_UPDATE, ConditionHelper.create("code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker.getSql()).append("\n");
                    }

                    mapper1.put("or_revoke", 1);
                    if (sqlMaker1.make(SqlMaker.TYPE_UPDATE,  ConditionHelper.create("org_code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker1.getSql()).append("\n");
                    }

                    break;
                case "启用":

                    mapper.put("isDisabled", "false");
                    if (sqlMaker.make(SqlMaker.TYPE_UPDATE, ConditionHelper.create("code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker.getSql()).append("\n");
                    }

                    mapper1.put("or_revoke", 0);
                    if (sqlMaker1.make(SqlMaker.TYPE_UPDATE,  ConditionHelper.create("org_code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker1.getSql()).append("\n");
                    }


                    break;
                case "删除":
                    if (sqlMaker.make(SqlMaker.TYPE_DELETE, ConditionHelper.create("code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker.getSql()).append("\n");
                    }
                    if (sqlMaker1.make(SqlMaker.TYPE_DELETE, ConditionHelper.create("org_code", "=", map.get("sorg_code")))) {
                        builder.append(sqlMaker1.getSql()).append("\n");
                    }
                    break;
                default:
                    System.out.println(map.get("sorg_is_disabled"));
            }

            TextUtils.textToClipboard(builder.toString());


        }
    }


}
